﻿@model IEnumerable<Codingwell.DevText.Model.Entities.ArticleCategory>
@{
	ViewBag.Title = "发表文章";
	Layout = "~/Views/Shared/_Layout.cshtml";
}
@section LocationPath{
	<a class="title" href="/">Devtext.com</a> » <a href="/home/blogs">博客</a> » 发表文章
}
<div class="fl user_left">
	@{Html.RenderAction("LeftNavigtion", "UserNavigation");}
</div>
<div class="fr user_right">
	<h1 class="user_title">
		发表文章</h1>
	<div class="user_tab">
		<ul>
			<li ><a href="/home/blogs">全站文章</a></li>
			<li ><a href="/home/blogs/my">我的文章</a></li>
			<li class="now"><a href="/home/blogs/post">发表文章</a></li>
		</ul>
	</div>
	<div class="user_con">
		<div class="fl">
			<div class="user_con_left">
			<div>
				<div class="mt5">
					<label>
						标题：</label>@Html.TextBox("txtTitle", "", new { @class = "text-input wp100", @maxlength = "200" })</div>
				<div class="mt5">
					<label>
						访问路径：</label>@Html.TextBox("txtPath", "", new { @class = "text-input wp100", @maxlength = "200" })</div>
				<div class="mt5">
					<label>
						内容：</label>@Html.TextArea("txtEditorBody", "", new { @class = "text-input wp100", @rows = "15" })</div>
				<div class="mt5">
					<label>
						缩略：</label>@Html.TextArea("txtSummary", "", new { @class = "text-input wp100", @rows = "5", @maxlength = "500" })</div>
				<div class="mt5">
					<label>
						Meta Keywords：</label>@Html.TextBox("txtKeywords", "", new { @class = "text-input wp100", @maxlength = "100" })</div>
				<div class="mt5">
					<label>
						Meta Description：</label>@Html.TextBox("txtDescription", "", new { @class = "text-input wp100", @maxlength = "150" })</div>
				<div class="mt5"><label>分类：</label><div>@foreach (var cate in Model) { 
											<input class="category" type="checkbox" id="@cate.ID" />@cate.Name
											}</div></div>
				<div class="mt5">
					<label>
						来源：</label>@Html.TextBox("txtWebFrom", "", new { @class = "text-input", @maxlength = "50" })</div>
				<div class="mt5">
					<label>
						网址：</label>@Html.TextBox("txtWebFromAddress", "", new { @class = "text-input wp80", @maxlength = "150" })</div>
				<div class="mtb5">
					<button id="btnOK" class="butn_save" onclick="Submit();">
						<span>发表</span></button></div>
			</div>
			</div>
		</div>
		<div class="fr user_con_right">
		</div>
	</div>
</div>
<div class="clearfix">
</div>
<script src="/Editor/kindeditor40/kindeditor-min.js" type="text/javascript"></script>
<script src="/Editor/kindeditor40/lang/zh_CN.js" type="text/javascript"></script>
<script type="text/javascript">
	var editor;

	KindEditor.ready(function (K) {
		editor = K.create('#txtEditorBody');
	});

	function Submit() {
		if ($.trim($("#txtTitle").val()).length <= 0) {
			alert("请输入资讯标题");
			return;
		}

		editor.sync();
		var content = $("#txtEditorBody").val();
		if ($.trim(content).length <= 0) {
			alert("请输入资讯内容");
			return;
		}
		if ($.trim($("#txtSummary").val()).length <= 0) {
			alert("请输入资讯的缩略");
			return;
		}
		var cates = [];
		$("input.category:checkbox:checked").each(function (i, e) {
			var cate = {
				ID: $(e).attr("ID")
			};
			cates.push(cate);
		});

		var news = {
			Title: $.trim($("#txtTitle").val()),
			Path: $.trim($("#txtPath").val()),
			Summary: $.trim($("#txtSummary").val()),
			ArticleContent: $.trim(content),
			WebFrom: $.trim($("#txtWebFrom").val()),
			WebFromAddress: $.trim($("#txtWebFromAddress").val()),
			MetaKeywords: $.trim($("#txtKeywords").val()),
			MetaDescription: $.trim($("#txtDescription").val()),
			ArticleCategories: cates
		};
		$.post("/home/blogs/submitpost", { json: JSON.stringify(news) }, function (data) {
			if (data.success) {
				alert(data.message);
				location.replace("/home/blogs/my");
			} else {
				alert(data.message);
			}
		}, "json");
	}
</script>
